﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using gfVehicleLibraryAJ;
using ConvertInfo;
using ProcessManage;
using AJNetLib;

namespace AJNetDll_QCLA
{
    public class QueryVehicle : IQueryVehicle
    {
        public ReturnInfo QueryByJKId(QueryCondition queryCondition)
        {
            ReturnInfo retInfo = new ReturnInfo();
            try
            {
                string strJKID = queryCondition.DicQueryPara["jkid"];
                switch (strJKID)
                {
                    case "18J52":
                        Vehicle_18J52_Para m_18J52_Para = Get_18J52_FromDic(queryCondition.DicQueryPara);
                        Vehicle_18J52_Result m_Result_18J52 = Query_18J52(m_18J52_Para);
                        retInfo.IsSucessful = m_Result_18J52.code == "1" ? true : false;
                        if (retInfo.IsSucessful)
                        {
                            Dictionary<string, string> dicRet = new Dictionary<string, string>();
                            dicRet.Add("HPHM", m_Result_18J52.hphm);
                            dicRet.Add("HPZLDH", m_Result_18J52.hpzl);
                            dicRet.Add("VIN", m_Result_18J52.clsbdh);
                            dicRet.Add("CLZLDH", m_Result_18J52.cllx);
                            dicRet.Add("JYLBDH", m_Result_18J52.jylb);
                            if (m_Result_18J52.syr != null)
                            {
                                dicRet.Add("SYR", m_Result_18J52.syr);
                            }
                            dicRet.Add("SYXZDH", m_Result_18J52.syxz);
                            dicRet.Add("PP", m_Result_18J52.clpp1);
                            dicRet.Add("XH", m_Result_18J52.clxh);
                            dicRet.Add("FDJH", m_Result_18J52.fdjh);
                            dicRet.Add("CCDJRQ", m_Result_18J52.ccdjrq.ToString("yyyy-MM-dd"));
                            dicRet.Add("CCRQ", m_Result_18J52.ccrq.ToString("yyyy-MM-dd"));
                            dicRet.Add("CYS", m_Result_18J52.zkrs.ToString());
                            if (m_Result_18J52.csys != null)
                            {
                                dicRet.Add("CSYSDH", m_Result_18J52.csys.ToString());
                            }
                            dicRet.Add("ZZS", m_Result_18J52.zs.ToString());
                            dicRet.Add("ZZL", m_Result_18J52.zzl.ToString());
                            dicRet.Add("ZBZL", m_Result_18J52.zbzl.ToString());
                            dicRet.Add("HDZH", m_Result_18J52.hdzzl.ToString());
                            dicRet.Add("CSC", m_Result_18J52.cwkc.ToString());
                            dicRet.Add("CSG", m_Result_18J52.cwkg.ToString());
                            dicRet.Add("CSK", m_Result_18J52.cwkk.ToString());
                            dicRet.Add("DLY", string.IsNullOrEmpty(m_Result_18J52.wjy) ? string.Empty : m_Result_18J52.wjy.ToString());
                            dicRet.Add("DLYSZH", string.IsNullOrEmpty(m_Result_18J52.dlysfzh) ? string.Empty : m_Result_18J52.dlysfzh.ToString());
                            dicRet.Add("ZXZLXDH", m_Result_18J52.sfqszxz);
                            dicRet.Add("QDXSDH", m_Result_18J52.qdxs);
                            dicRet.Add("ZXZXJXSDH", m_Result_18J52.zxzxjxs);
                            dicRet.Add("QZDZDH", m_Result_18J52.qzdz);
                            dicRet.Add("YGGSNFKTDH", m_Result_18J52.ygddtz);
                            dicRet.Add("QDZWZ", m_Result_18J52.qdzwz);
                            dicRet.Add("ZCZWZ", m_Result_18J52.zczw);
                            dicRet.Add("RLLBDH", m_Result_18J52.rlzl);
                            dicRet.Add("JYCS", m_Result_18J52.jycs.ToString());
                            dicRet.Add("JYXM", m_Result_18J52.jyxm);
                            dicRet.Add("AJLSH", m_Result_18J52.jylsh);
                            dicRet.Add("LJXSLC", m_Result_18J52.lcbds);
                            dicRet.Add("WJPD", m_Result_18J52.wjpd);
                            dicRet.Add("XBWJBHGX", m_Result_18J52.xbwjbhgx);
                            dicRet.Add("WJY", m_Result_18J52.wjy);
                            dicRet.Add("RGWJXM", m_Result_18J52.rgwjxm);
                            dicRet.Add("RGDTDPXM", m_Result_18J52.rgdtdpxm);
                            dicRet.Add("WGBHGYY", m_Result_18J52.wgbhgyy);
                            dicRet.Add("DTDPPD", m_Result_18J52.dtdppd);
                            dicRet.Add("XBDTDPBHGX", m_Result_18J52.xbdtdpbhgx);
                            dicRet.Add("DTDPJYY", m_Result_18J52.dtdpjyy);
                            dicRet.Add("DTDPBHGYY", m_Result_18J52.dpdtbhgyy);
                            dicRet.Add("ZDFSDH", m_Result_18J52.zzly);
                            if (m_Result_18J52.gl.HasValue)
                            {
                                dicRet.Add("FDJGL", m_Result_18J52.gl.ToString());
                            }
                            dicRet.Add("QLJ", m_Result_18J52.qlj.ToString());
                            dicRet.Add("ZJ", m_Result_18J52.zj.ToString());
                           
                            retInfo.DicRet = dicRet;
                        }
                        else
                        {
                            retInfo.Message = m_Result_18J52.message;
                        }
                        break;
                }
            }
            catch (Exception ex)
            {
                retInfo.IsSucessful = false;
                retInfo.Message = ex.Message;
            }

            return retInfo;
        }

        private Vehicle_18J52_Result Query_18J52(Vehicle_18J52_Para para_18J52)
        {
            AJ_ReadProcess readProcess = new AJ_ReadProcess();
            Vehicle_18J52_Result result_18J52 = readProcess.AJ_Read_18J52(para_18J52);
            return result_18J52;
        }

        #region 得到字典集合
        /// <summary>
        /// Dictionary change to 18C51 Para
        /// </summary>
        /// <param name="dic"></param>
        /// <returns></returns>
        private Vehicle_18J52_Para Get_18J52_FromDic(Dictionary<string, string> dic)
        {
            ModelReflection m_ModelReflection = new ModelReflection();
            Vehicle_18J52_Para m_18J52_Para = new Vehicle_18J52_Para();

            m_18J52_Para = m_ModelReflection.DictionaryToModel(m_18J52_Para, dic);

            return m_18J52_Para;
        }
        #endregion
    }
}
